// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  // API 调用都保持和云函数当前所在环境一致
  env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database();

const _ = db.command;

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext();
  let watchArray = ["4e1e2ad55f6607270046a3580680c737", "4e1e2ad55f6607270046a35746f5b560", "0413e9635f6757860004fd254e16954f"]
  let result = await db.collection("babyList").aggregate()
                    .lookup({
                        from: "findPersonList",
                        localField: "_id",
                        foreignField: "_id",
                        as: "list",
                    })
                    .match({ _id: _.in(watchArray) }).end();
  return result
}